package dcedit.util;

// Import Java JDK Classes
import java.io.StringWriter;
import javax.xml.bind.*;
import javax.xml.bind.annotation.*;

/** Data model class for encapsulating file line occurrences of a search term */
@XmlRootElement(name = "SearchTermOccurrence")
@XmlAccessorType(XmlAccessType.FIELD)
public class SearchTermOccurrence {
   private String fileName;
   private String fileLine;
   private int lineNumber;

   /** Constructor */
   public SearchTermOccurrence() {
      this("","",-1);
   } // END constructor

   /** Constructor */
   public SearchTermOccurrence(String fileName,String fileLine,int lineNumber) {
      setFileName(fileName);
      setFileLine(fileLine);
      setLineNumber(lineNumber);
   } // END constructor

   /** getFileName method */
   public String getFileName() {
      return fileName;
   } // END getFileName method

   /** setFileName method */
   public void setFileName(String fileName) {
      this.fileName = fileName;
   } // END setFileName method

   /** getFileLine method */
   public String getFileLine() {
      return fileLine;
   } // END getFileLine method

   /** setFileLine method */
   public void setFileLine(String fileLine) {
      this.fileLine = fileLine;
   } // END setFileLine method

   /** getLineNumber method */
   public int getLineNumber() {
      return lineNumber;
   } // END getLineNumber method

   /** setLineNumber method */
   public void setLineNumber(int lineNumber) {
      this.lineNumber = lineNumber;
   } // END setLineNumber method

   @Override
   public String toString() {
      StringBuilder str = new StringBuilder();
      str.append(SearchTermOccurrence.class.getSimpleName());
      str.append(" [");                                      str.append(Constants.NEW_LINE);
      str.append("\tfileName   = "); str.append(fileName);   str.append(Constants.NEW_LINE);
      str.append("\tfileLine   = "); str.append(fileLine);   str.append(Constants.NEW_LINE);
      str.append("\tlineNumber = "); str.append(lineNumber); str.append(Constants.NEW_LINE);
      str.append("]");                                       str.append(Constants.NEW_LINE);
      return str.toString();
   } // END toString method

   /** toXMLString method */
   public String toXMLString() throws JAXBException {
      StringWriter writer = new StringWriter();
      JAXBContext context = JAXBContext.newInstance(this.getClass());
      Marshaller marshaller = context.createMarshaller();
      marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
      marshaller.marshal(this, writer);
      return writer.toString();
   } // END toXMLString
} // END class Occurrence
